<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const patients = [
            {
                id: '001',
                name: 'Alice',
                age: 34,
                gender: 'F',
                bloodPressure: {
                    systolic: 120,
                    diastolic: 80
                },
                hasDiabetes: false
            },
            {
                id: '002',
                name: 'Bob',
                age: 47,
                gender: 'M',
                bloodPressure: {
                    systolic: 140,
                    diastolic: 90
                },
                hasDiabetes: true
            },
            {
                id: '003',
                name: 'Charlie',
                age: 55,
                gender: 'M',
                bloodPressure: {
                    systolic: 130,
                    diastolic: 95
                },
                hasDiabetes: false
            }
        ];


        // Output:
        // [
        //   {
        //     id: '001',
        //     name: 'Alice',
        //     age: 34,
        //     gender: 'F',
        //     bloodPressure: { systolic: 120, diastolic: 80 },
        //     hasDiabetes: false
        //   },
        //   {
        //     id: '003',
        //     name: 'Charlie',
        //     age: 55,
        //     gender: 'M',
        //     bloodPressure: { systolic: 130, diastolic: 95 },
        //     hasDiabetes: false
        //   }
        // ]

        function getHighBloodPressurePatients(
            patients,
            systolicThreshold,
            diastolicThreshold
        ) {
            let arr = patients.filter(
                (item) =>
                    item.bloodPressure.systolic > systolicThreshold ||
                    item.bloodPressure.diastolic > diastolicThreshold
            )
            arr.sort((a, b) => {
                if (a.name > b.name) {
                    return 1
                }
                if (a.name < b.name) {
                    return -1
                }
            })
            return arr
        }

        const highBloodPressurePatients = getHighBloodPressurePatients(
            patients,
            125,
            85
        )
        console.log(highBloodPressurePatients)
    </script>
</body>

</html>